<?php

namespace app\api\controller;

use app\common\business\User as userBn;
use app\extra\Duiba\Duiba as duibaBn;
use app\common\business\user\Point as PointBn;
class Home extends \app\common\controller\HomeBase {

    /**
     * 首页
     */
    public function index() {
        try {
            $userinfo = $this->_validLogininfo();
            $data['user']=$userinfo;
//            $sys = F('System');
            $post['user_id']=$userinfo['user_id'];
            $data['note']=userBn::runningindex($post);
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /**
     * 首页分享
     */
    public function shareindex() {
        try {

            $data=array(
                'share_title'=>'竞猜2018世界杯，百万奖金等你来领',
                'share_img'=>'https://qhimg.qiu7.net/sjb_duobao/shijiebeijingcai.jpg'
            );
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /**
     * 复活分享
     */
    public function relife() {
        try {

            $data=array(
                'share_title'=>'动动手指，好友复活，参与世界杯竞猜',
                'share_img'=>'https://qhimg.qiu7.net/sjb_duobao/shijiebeijingcai.jpg'
            );
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /**
     * 推演分享
     */
    public function deduction() {
        try {

            $data=array(
                'share_title'=>'选出心中冠军 瓜分百万奖金',
                'share_img'=>'https://qhimg.qiu7.net/sjb_duobao/shijiebeijingcai.jpg'
            );
            $this->_echoSuccessMessage('', $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
    /**
     * 免登陆地址接口
     *
     */
    public function duibaindex() {
        try {
            $user_id = $this->_isLogin();
            $duibaBn = new duibaBn();;
            $data = $duibaBn->buildRedirectAutoLoginRequest($user_id, '');
            $this->_echoSuccessMessage("", $data);
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }

    /**
     * 用户积分扣除接口
     *
     */
    public function parseCreditConsume() {
        try {
            $duibaBn = new duibaBn();
            $request_array = input();
            $data = $duibaBn->parseCreditConsume($request_array);
            $data['credits'] = PointBn::mypoint($request_array['uid']);
            $this->_echoSuccessMessage("", $data, 1);
        } catch (\Exception $e) {
            $data['credits'] = PointBn::mypoint($request_array['uid']);
            $this->_echoErrorMessage($e->getMessage(), $e->getCode(), 1, $data);
        }
    }

    /**
     * 订单兑换成功/失败消息的接收接口
     *
     */
    public function parseCreditNotify() {
        try {
            $duibaBn = new duibaBn();
            $request_array = input();
            $duibaBn->parseCreditNotify($request_array);
            $this->_echoDuibaMessage();
        } catch (\Exception $e) {
            $this->_echoErrorMessage($e->getMessage(), $e->getCode());
        }
    }
}
